import {
  Controller,
  Post,
  Body,
  BadRequestException,
  Get,
  Req
} from '@nestjs/common'
import { ApiOperation, ApiBearerAuth, ApiTags } from '@nestjs/swagger'
import { createArticleDto } from './dto/create-article.dto'
import { ArticleService } from './article.service'
import { CurrentUser } from 'src/common/decorator/user.decorator'
import { UserEntity } from 'src/entities/user.entity'

@Controller('article')
@ApiTags('帖子')
export class ArticleController {
  constructor(private readonly ArticleService: ArticleService) {}

  @Post()
  @ApiOperation({ summary: '创建帖子' })
  @ApiBearerAuth()
  async createArticle(
    @Req() req,
    @Body() body: createArticleDto,
    @CurrentUser() user: UserEntity,
  ): Promise<any> {
    console.log(req)
    const [err, article] = await this.ArticleService.create(body, user)
    if (!err) {
      return article
    } else {
      throw new BadRequestException('请求参数不正确')
    }
  }
}
